package com.wwz.controller;

import com.wwz.entity.Result;
import com.wwz.entity.Role;
import com.wwz.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/role")
@Api(tags = "角色控制器")
public class RoleController {

    @Resource
    private IRoleService roleService;

    @ApiOperation("添加或修改")
    @PostMapping("addOrUpData")
    public Result addOrUpData(@RequestBody Role role){
        roleService.addOrUpData(role);
        return Result.ok("操作成功");
    }

    @ApiOperation("角色列表")
    @GetMapping("list")
    public Result getRoles(){
        return Result.ok(roleService.list());
    }

    @ApiOperation("删除角色")
    @DeleteMapping("delete/{id}")
    public Result deleteRole(@PathVariable String id){
        roleService.removeById(id);
        return Result.ok("删除成功");
    }
}
